import numpy as np
import cv2
import os

data_path = "F:\\data\\wow\\img_data\\train\\images"  # 数据集路径
img_height, img_width = 448, 448  # 图片尺寸

# 初始化变量
img_count = 0
img_sum = np.zeros((3,))
img_squared_sum = np.zeros((3,))

# 遍历数据集文件夹中的所有图片
for root, dirs, files in os.walk(data_path):
    for file in files:
        img_path = os.path.join(root, file)
        img = cv2.imread(img_path).astype(np.float32) / 255
        img = cv2.resize(img, (img_width, img_height))  # 缩放图片至指定尺寸
        img_count += 1
        img_sum += np.sum(img, axis=(0, 1))
        img_squared_sum += np.sum(img ** 2, axis=(0, 1))

# 计算每个通道的均值和标准差
channel_mean = img_sum / (img_count * img_height * img_width)
channel_std = np.sqrt((img_squared_sum / (img_count * img_height * img_width)) - (channel_mean ** 2))

print('每个通道的均值：', channel_mean)
print('每个通道的标准差：', channel_std)
